<!DOCTYPE html><html><head>
<title>string::token::shell - Text and string utilities</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'token_shell.man' by tcllib/doctools with format 'html'
   -->
<!-- string::token::shell.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
&#124; <a href="../../../../toc.html">Main Table Of Contents</a>
&#124; <a href="../../../toc.html">Table Of Contents</a>
&#124; <a href="../../../../index.html">Keyword Index</a>
&#124; <a href="../../../../toc0.html">Categories</a>
&#124; <a href="../../../../toc1.html">Modules</a>
&#124; <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">string::token::shell(n) 1.2 tcllib &quot;Text and string utilities&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>string::token::shell - Parsing of shell command line</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.5</b></li>
<li>package require <b class="pkgname">string::token::shell <span class="opt">?1.2?</span></b></li>
<li>package require <b class="pkgname">string::token <span class="opt">?1?</span></b></li>
<li>package require <b class="pkgname">fileutil</b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">::string token shell</b> <span class="opt">?<b class="option">-indices</b>?</span> <span class="opt">?<b class="option">-partial</b>?</span> <span class="opt">?--?</span> <i class="arg">string</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>This package provides a command which parses a line of text using
basic <b class="syscmd">sh</b>-syntax into a list of words.</p>
<p>The complete set of procedures is described below.</p>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">::string token shell</b> <span class="opt">?<b class="option">-indices</b>?</span> <span class="opt">?<b class="option">-partial</b>?</span> <span class="opt">?--?</span> <i class="arg">string</i></a></dt>
<dd><p>This command parses the input <i class="arg">string</i> under the assumption of it
following basic <b class="syscmd">sh</b>-syntax.
The result of the command is a list of words in the <i class="arg">string</i>.
An error is thrown if the input does not follow the allowed syntax.
The behaviour can be modified by specifying any of the two options
<b class="option">-indices</b> and <b class="option">-partial</b>.</p>
<dl class="doctools_options">
<dt><b class="option">--</b></dt>
<dd><p>When specified option parsing stops at this point. This option is
needed if the input <i class="arg">string</i> may start with dash. In other words,
this is pretty much required if <i class="arg">string</i> is user input.</p></dd>
<dt><b class="option">-indices</b></dt>
<dd><p>When specified the output is not a list of words, but a list of
4-tuples describing the words. Each tuple contains the type of the
word, its start- and end-indices in the input, and the actual text of
the word.</p>
<p>Note that the length of the word as given by the indices can
differ from the length of the word found in the last element of the
tuple. The indices describe the words extent in the input, including
delimiters, intra-word quoting, etc. whereas for the actual text of
the word delimiters are stripped, intra-word quoting decoded, etc.</p>
<p>The possible token types are</p>
<dl class="doctools_definitions">
<dt><b class="const">PLAIN</b></dt>
<dd><p>Plain word, not quoted.</p></dd>
<dt><b class="const">D:QUOTED</b></dt>
<dd><p>Word is delimited by double-quotes.</p></dd>
<dt><b class="const">S:QUOTED</b></dt>
<dd><p>Word is delimited by single-quotes.</p></dd>
<dt><b class="const">D:QUOTED:PART</b></dt>
<dd></dd>
<dt><b class="const">S:QUOTED:PART</b></dt>
<dd><p>Like the previous types, but the word has no closing quote, i.e. is
incomplete. These token types can occur if and only if the option
<b class="option">-partial</b> was specified, and only for the last word of the
result. If the option <b class="option">-partial</b> was not specified such
incomplete words cause the command to thrown an error instead.</p></dd>
</dl></dd>
<dt><b class="option">-partial</b></dt>
<dd><p>When specified the parser will accept an incomplete quoted word
(i.e. without closing quote) at the end of the line as valid instead
of throwing an error.</p></dd>
</dl>
<p>The basic shell syntax accepted here are unquoted, single- and
double-quoted words, separated by whitespace. Leading and trailing
whitespace are possible too, and stripped.
Shell variables in their various forms are <em>not</em> recognized, nor
are sub-shells.
As for the recognized forms of words, see below for the detailed
specification.</p>
<dl class="doctools_definitions">
<dt><b class="const">single-quoted word</b></dt>
<dd><p>A single-quoted word begins with a single-quote character, i.e.
<b class="const">'</b> (ASCII 39) followed by zero or more unicode characters not a
single-quote, and then closed by a single-quote.</p>
<p>The word must be followed by either the end of the string, or
whitespace. A word cannot directly follow the word.</p></dd>
<dt><b class="const">double-quoted word</b></dt>
<dd><p>A double-quoted word begins with a double-quote character, i.e.
<b class="const">&quot;</b> (ASCII 34) followed by zero or more unicode characters not a
double-quote, and then closed by a double-quote.</p>
<p>Contrary to single-quoted words a double-quote can be embedded
into the word, by prefacing, i.e. escaping, i.e. quoting it with a
backslash character <b class="const">\</b> (ASCII 92). Similarly a backslash
character must be quoted with itself to be inserted literally.</p></dd>
<dt><b class="const">unquoted word</b></dt>
<dd><p>Unquoted words are not delimited by quotes and thus cannot contain
whitespace or single-quote characters. Double-quote and backslash
characters can be put into unquoted words, by quting them like for
double-quoted words.</p></dd>
<dt><b class="const">whitespace</b></dt>
<dd><p>Whitespace is any unicode space character.
This is equivalent to <b class="cmd">string is space</b>, or the regular
expression \\s.</p>
<p>Whitespace may occur before the first word, or after the last word. Whitespace must occur between adjacent words.</p></dd>
</dl></dd>
</dl>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>textutil</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#bash">bash</a>, <a href="../../../../index.html#lexing">lexing</a>, <a href="../../../../index.html#parsing">parsing</a>, <a href="../../../../index.html#shell">shell</a>, <a href="../../../../index.html#string">string</a>, <a href="../../../../index.html#tokenization">tokenization</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Text processing</p>
</div>
</div></body></html>
